package com.example.partyfee.controller;

import com.example.partyfee.dto.PartyFeeCalculationDTO;
import com.example.partyfee.dto.PartyFeeQueryDTO;
import com.example.partyfee.dto.Result;
import com.example.partyfee.entity.PartyFee;
import com.example.partyfee.service.PartyFeeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.validation.Valid;
import java.io.IOException;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/party-fees")
@RequiredArgsConstructor
public class PartyFeeController {
    
    private final PartyFeeService partyFeeService;
    
    @PostMapping("/calculate")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<Void> calculatePartyFees(@Valid @RequestBody PartyFeeCalculationDTO calculationDTO) {
        partyFeeService.calculatePartyFees(calculationDTO);
        return Result.success();
    }
    
    @GetMapping
    public Result<IPage<PartyFee>> getPartyFees(PartyFeeQueryDTO queryDTO) {
        return Result.success(partyFeeService.getPartyFees(queryDTO));
    }
    
    @GetMapping("/export")
    public void exportPartyFees(PartyFeeQueryDTO queryDTO, HttpServletResponse response)
        throws IOException {
        partyFeeService.exportPartyFees(queryDTO, response);
    }
} 